﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 10:25 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NHibernate;
using System.Collections.Generic;
using System.Data;
using Miming.Model.Dao.Interface;

namespace Miming.Model.Dao.NHibernate
{
	/// <summary>
	/// Description of NHibernatePurchaseOrderDao.
	/// </summary>
	public class NHibernatePurchaseOrderDao : IPurchaseOrderDao
	{
		public NHibernatePurchaseOrderDao()
		{
		}
		
		public void SaveOrUpdate(PurchaseOrder order)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.SaveOrUpdate(order);
			session.Flush();
		}
		
		public void Delete(PurchaseOrder order)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.Delete(order);
			session.Flush();
		}
		
		public PurchaseOrder ReadByPk(int id)
		{
			return NHibernateHelper.OpenSession().Load<PurchaseOrder>(id);
		}
		
		public IList<PurchaseOrder> FindAll()
		{
			return NHibernateHelper.OpenSession().CreateCriteria(typeof(PurchaseOrder)).List<PurchaseOrder>();
		}
	}
}
